﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using com.hk.validate.Common;
using System.Collections;

namespace WebApplication1.Ajax
{
    /// <summary>
    /// ValidateAjax 的摘要说明
    /// </summary>
    public class ValidateAjax : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var form = context.Request.Form;
            ArrayList al = new ArrayList();
            foreach (var k in form.AllKeys)
            {
                string v = form[k];
                if (!RequiredValidator.Validate(v))
                {
                    al.Add(k + " is Required!");
                }
            }
            if (al.Count > 0)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write(string.Join(" ", al.ToArray()));
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("OK");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}